package com.fowo.api.flow.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fowo.api.flow.entity.WorkFlow;
import com.fowo.api.flow.mapper.WorkFlowMapper;
import com.fowo.api.flow.service.WorkFlowService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @fileName: WorkFlowServiceImpl
 * @Description: 代码目的，作用，如何工作
 * @Author: pzh
 * @Date: 2023/5/4 0004 9:48
 */
@Service
public class WorkFlowServiceImpl extends ServiceImpl<WorkFlowMapper, WorkFlow> implements WorkFlowService {


    @Override
    public WorkFlow queryWf(Long recordId, String formName) {
        if (Objects.isNull(recordId) || StringUtils.isBlank(formName)) {
            return new WorkFlow();
        }
        LambdaQueryWrapper<WorkFlow> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WorkFlow::getRecordId, recordId);
        wrapper.eq(WorkFlow::getFormName, formName);
        return list(wrapper).stream().findFirst().orElse(null);
    }

    @Override
    public List<WorkFlow> queryWfList(List<Long> recordIds, List<String> formNames) {
        if (CollectionUtils.isEmpty(recordIds) || CollectionUtils.isEmpty(formNames)) {
            return Collections.emptyList();
        }
        LambdaQueryWrapper<WorkFlow> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(WorkFlow::getRecordId, recordIds);
        wrapper.in(WorkFlow::getFormName, formNames);
        return list(wrapper);
    }

    @Override
    public List<WorkFlow> queryWfListByStatus(Integer wfStatus, String formNames) {

        if (Objects.isNull(wfStatus) || StringUtils.isBlank(formNames)) {
            return Collections.emptyList();
        }
        LambdaQueryWrapper<WorkFlow> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WorkFlow::getWfStatus, wfStatus);
        wrapper.eq(WorkFlow::getFormName, formNames);
        return list(wrapper);
    }


}
